package com.study.cfbeans;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;

@Configuration
public class ConfigBean {

	@Bean
	@LoadBalanced //启用ribbon的负载均衡
	public RestTemplate getRestTemplate() {
		return new RestTemplate();
	}
	
	/** 
	 * 自定义负载均衡算法
	 * 默认是轮询
	 * <p>Title: myRule<／p>
	 * <p>Description: <／p>
	 * @return
	 */
	@Bean
	public IRule myRule() {
		//RoundRobinRule 轮询算法
		//使用随机算法，可自定义算法，继承AbstractLoadBalancerRule
		return new RandomRule();
	}
}
